﻿using Microsoft.Xna.Framework;

namespace Phoenix.Xna.Framework.FrameworkExtensions
{
    public static class MatrixExtensions
    {
        public static Vector3 ToVector3(this Matrix obj)
        {
            Quaternion q = Quaternion.CreateFromRotationMatrix(obj);
            return new Vector3(q.X, q.Y, q.Z);
        }

        public static Vector3 ToEulerAngle(this Matrix obj)
        {
            Vector3 translation;
            Vector3 scale;
            Quaternion rotation;
            obj.Decompose(out scale, out rotation, out translation);
            Vector3 eulerVector = rotation.ToEulerAngle();
            float pitch = eulerVector.X;
            eulerVector.X = eulerVector.Y;
            eulerVector.Y = pitch;
            return eulerVector;
        }
    }
}